/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fi.uba.tecnicas.diseno.tp2.ui;

import java.awt.Color;

import javax.swing.table.DefaultTableModel;

import modelo.Cupon;
import modelo.Oferta;
import modelo.OrdenDeCompra;
import modelo.Producto;
import modelo.Venta;

/**
 * 
 * @author federico
 */
public class RegisterBoxUI extends javax.swing.JFrame {

	final static String OPEN = "ABIERTA";
	final static String CLOSED = "CERRADA";
	final static String CREDIT_CARD = "Tarjeta";
	final static String PRODUCT_ID = "Código Interno";
	final static String PRODUCT_DESCRIPTION = "Descripción";
	final static String PRODUCT_COUNT = "Cantidad";
	final static String PRODUCT_PRICE = "Precio de Lista";
	final static String PRODUCT_TOTAL_PRICE = "Importe";

	RegisterBox registerBox = new RegisterBox(new Integer(1), "Sucursal 1");

	/**
	 * Creates new form Tp2RegisterBoxUI
	 */
	public RegisterBoxUI() {
		initComponents();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		registerBoxStatePanel = new javax.swing.JPanel();
		registerStateLable = new javax.swing.JLabel();
		cashRegisterState = new javax.swing.JTextField();
		cashRegisterStateButton = new javax.swing.JButton();
		purchaseDetailsPanel = new javax.swing.JPanel();
		totalLabel = new javax.swing.JLabel();
		totalsField = new javax.swing.JTextField();
		discountsPanel = new javax.swing.JPanel();
		jScrollPane1 = new javax.swing.JScrollPane();
		discountsTable = new javax.swing.JTable();
		toolBar2 = new javax.swing.JToolBar();
		idCuponLabel = new javax.swing.JLabel();
		addCuponField = new javax.swing.JTextField();
		addNewCuponButton = new javax.swing.JButton();
		jSeparator1 = new javax.swing.JToolBar.Separator();
		generateCupons = new javax.swing.JCheckBox();
		totalDiscountsField = new javax.swing.JTextField();
		discountsLabel = new javax.swing.JLabel();
		cuponGeneratedLabel = new javax.swing.JLabel();
		cuponGeneratedField = new javax.swing.JTextField();
		productsPanel = new javax.swing.JPanel();
		toolBar1 = new javax.swing.JToolBar();
		idProductLabel = new javax.swing.JLabel();
		addProductField = new javax.swing.JTextField();
		addNewProductButton = new javax.swing.JButton();
		deleteSelectedProductButton = new javax.swing.JButton();
		subtotalLabel = new javax.swing.JLabel();
		subTotalField = new javax.swing.JTextField();
		jScrollPane2 = new javax.swing.JScrollPane();
		productsTable = new javax.swing.JTable();
		initPurchaseButton = new javax.swing.JButton();
		viewTotalsButton = new javax.swing.JButton();
		confirmPurchaseButton = new javax.swing.JButton();
		companyDetailsPanel = new javax.swing.JPanel();
		dateLabel = new javax.swing.JLabel();
		ticketNumberLabel = new javax.swing.JLabel();
		hourLabel = new javax.swing.JLabel();
		dateField = new javax.swing.JTextField();
		companyLabel = new javax.swing.JLabel();
		branchOfficeLabel = new javax.swing.JLabel();
		branchOfficeComboBox = new javax.swing.JComboBox();
		companyNameField = new javax.swing.JTextField();
		ticketNumberField = new javax.swing.JTextField();
		paymentLabel = new javax.swing.JLabel();
		registerBoxLabel = new javax.swing.JLabel();
		registerBoxNumberField = new javax.swing.JTextField();
		bankLabel = new javax.swing.JLabel();
		paymentComboBox = new javax.swing.JComboBox();
		bankComboBox = new javax.swing.JComboBox();
		clientTypeBomboBox = new javax.swing.JComboBox();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		registerBoxStatePanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

		registerStateLable.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		registerStateLable.setText("Estado");

		cashRegisterState.setEditable(false);
		cashRegisterState.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
		cashRegisterState.setForeground(new java.awt.Color(255, 0, 0));
		cashRegisterState.setHorizontalAlignment(javax.swing.JTextField.CENTER);
		cashRegisterState.setText("CERRADA");
		cashRegisterState.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

		cashRegisterStateButton.setText("Abrir/CerrarCaja");
		cashRegisterStateButton.setActionCommand("");
		cashRegisterStateButton.setBorder(null);
		cashRegisterStateButton.setFocusable(false);
		cashRegisterStateButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		cashRegisterStateButton.setPreferredSize(new java.awt.Dimension(70, 70));
		cashRegisterStateButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		cashRegisterStateButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				cashRegisterStateButtonActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout registerBoxStatePanelLayout = new javax.swing.GroupLayout(registerBoxStatePanel);
		registerBoxStatePanel.setLayout(registerBoxStatePanelLayout);
		registerBoxStatePanelLayout.setHorizontalGroup(registerBoxStatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						javax.swing.GroupLayout.Alignment.TRAILING,
						registerBoxStatePanelLayout
								.createSequentialGroup()
								.addGroup(
										registerBoxStatePanelLayout
												.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
												.addGroup(
														registerBoxStatePanelLayout
																.createSequentialGroup()
																.addContainerGap()
																.addComponent(cashRegisterStateButton, javax.swing.GroupLayout.DEFAULT_SIZE,
																		javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
												.addGroup(
														registerBoxStatePanelLayout
																.createSequentialGroup()
																.addGap(16, 16, 16)
																.addComponent(registerStateLable)
																.addGap(8, 8, 8)
																.addComponent(cashRegisterState, javax.swing.GroupLayout.DEFAULT_SIZE, 102,
																		Short.MAX_VALUE))).addContainerGap()));
		registerBoxStatePanelLayout.setVerticalGroup(registerBoxStatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						javax.swing.GroupLayout.Alignment.TRAILING,
						registerBoxStatePanelLayout
								.createSequentialGroup()
								.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addGroup(
										registerBoxStatePanelLayout
												.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(registerStateLable, javax.swing.GroupLayout.PREFERRED_SIZE, 30,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(cashRegisterState, javax.swing.GroupLayout.PREFERRED_SIZE, 30,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
								.addComponent(cashRegisterStateButton, javax.swing.GroupLayout.PREFERRED_SIZE, 34,
										javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap()));

		purchaseDetailsPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
		purchaseDetailsPanel.setEnabled(false);
		purchaseDetailsPanel.setName(""); // NOI18N

		totalLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
		totalLabel.setText("TOTAL A PAGAR");

		totalsField.setEditable(false);
		totalsField.setFont(new java.awt.Font("Ubuntu", 0, 24)); // NOI18N
		totalsField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
		totalsField.setEnabled(false);
		totalsField.setFocusable(false);

		discountsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Descuentos aplicados",
				javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial",
						1, 10), new java.awt.Color(1, 1, 1))); // NOI18N
		discountsPanel.setEnabled(false);

		discountsTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

		}, new String[] { "Porcentaje", "Descripción" }) {
			Class[] types = new Class[] { java.lang.String.class, java.lang.String.class };
			boolean[] canEdit = new boolean[] { false, false };

			public Class getColumnClass(int columnIndex) {
				return types[columnIndex];
			}

			public boolean isCellEditable(int rowIndex, int columnIndex) {
				return canEdit[columnIndex];
			}
		});
		discountsTable.setEnabled(false);
		jScrollPane1.setViewportView(discountsTable);
		discountsTable.getColumnModel().getColumn(0).setPreferredWidth(100);
		discountsTable.getColumnModel().getColumn(0).setMaxWidth(100);

		toolBar2.setFloatable(false);
		toolBar2.setRollover(true);

		idCuponLabel.setText("Código Cupón:");
		toolBar2.add(idCuponLabel);

		addCuponField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
		addCuponField.setToolTipText("");
		addCuponField.setEnabled(false);
		addCuponField.setMaximumSize(new java.awt.Dimension(100, 20));
		addCuponField.setMinimumSize(new java.awt.Dimension(100, 20));
		addCuponField.setPreferredSize(new java.awt.Dimension(80, 28));
		toolBar2.add(addCuponField);

		addNewCuponButton.setText("Agregar");
		addNewCuponButton.setFocusable(false);
		addNewCuponButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		addNewCuponButton.setMaximumSize(new java.awt.Dimension(70, 30));
		addNewCuponButton.setMinimumSize(new java.awt.Dimension(70, 30));
		addNewCuponButton.setPreferredSize(new java.awt.Dimension(70, 30));
		addNewCuponButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		addNewCuponButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				addNewCuponButtonActionPerformed(evt);
			}
		});
		toolBar2.add(addNewCuponButton);
		toolBar2.add(jSeparator1);

		generateCupons.setText("GenerarCupon");
		generateCupons.setEnabled(false);
		generateCupons.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				generateCuponsActionPerformed(evt);
			}
		});
		toolBar2.add(generateCupons);

		totalDiscountsField.setEditable(false);
		totalDiscountsField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
		totalDiscountsField.setEnabled(false);
		totalDiscountsField.setFocusable(false);
		totalDiscountsField.setMaximumSize(new java.awt.Dimension(100, 20));
		totalDiscountsField.setMinimumSize(new java.awt.Dimension(100, 20));
		totalDiscountsField.setPreferredSize(new java.awt.Dimension(100, 20));

		discountsLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
		discountsLabel.setText("Subtotal Descuentos");

		cuponGeneratedLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
		cuponGeneratedLabel.setText("Cupon Generado");

		cuponGeneratedField.setEditable(false);
		cuponGeneratedField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
		cuponGeneratedField.setEnabled(false);
		cuponGeneratedField.setFocusable(false);
		cuponGeneratedField.setMaximumSize(new java.awt.Dimension(100, 20));
		cuponGeneratedField.setMinimumSize(new java.awt.Dimension(100, 20));
		cuponGeneratedField.setPreferredSize(new java.awt.Dimension(100, 20));

		javax.swing.GroupLayout discountsPanelLayout = new javax.swing.GroupLayout(discountsPanel);
		discountsPanel.setLayout(discountsPanelLayout);
		discountsPanelLayout.setHorizontalGroup(discountsPanelLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addComponent(jScrollPane1)
				.addComponent(toolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
				.addGroup(
						javax.swing.GroupLayout.Alignment.TRAILING,
						discountsPanelLayout
								.createSequentialGroup()
								.addGap(0, 0, Short.MAX_VALUE)
								.addComponent(cuponGeneratedLabel)
								.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(cuponGeneratedField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addGap(18, 18, 18)
								.addComponent(discountsLabel)
								.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(totalDiscountsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
										javax.swing.GroupLayout.PREFERRED_SIZE).addGap(8, 8, 8)));
		discountsPanelLayout.setVerticalGroup(discountsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				javax.swing.GroupLayout.Alignment.TRAILING,
				discountsPanelLayout
						.createSequentialGroup()
						.addComponent(toolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(
								discountsPanelLayout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
										.addComponent(totalDiscountsField, javax.swing.GroupLayout.PREFERRED_SIZE, 28,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addComponent(discountsLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)
										.addGroup(
												discountsPanelLayout
														.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(cuponGeneratedField, javax.swing.GroupLayout.PREFERRED_SIZE, 28,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(cuponGeneratedLabel, javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
						.addGap(0, 0, Short.MAX_VALUE)));

		productsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Productos Comprados",
				javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial",
						1, 10), new java.awt.Color(1, 1, 1))); // NOI18N
		productsPanel.setEnabled(false);

		toolBar1.setFloatable(false);
		toolBar1.setRollover(true);

		idProductLabel.setText("Código Producto:");
		toolBar1.add(idProductLabel);

		addProductField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
		addProductField.setToolTipText("");
		addProductField.setEnabled(false);
		addProductField.setMaximumSize(new java.awt.Dimension(100, 20));
		addProductField.setMinimumSize(new java.awt.Dimension(100, 20));
		addProductField.setPreferredSize(new java.awt.Dimension(80, 28));
		toolBar1.add(addProductField);

		addNewProductButton.setText("Agregar");
		addNewProductButton.setFocusable(false);
		addNewProductButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		addNewProductButton.setMaximumSize(new java.awt.Dimension(70, 30));
		addNewProductButton.setMinimumSize(new java.awt.Dimension(70, 30));
		addNewProductButton.setName(""); // NOI18N
		addNewProductButton.setPreferredSize(new java.awt.Dimension(70, 30));
		addNewProductButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		addNewProductButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				addNewProductButtonActionPerformed(evt);
			}
		});
		toolBar1.add(addNewProductButton);

		deleteSelectedProductButton.setText("Borrar Seleccionado");
		deleteSelectedProductButton.setFocusable(false);
		deleteSelectedProductButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		deleteSelectedProductButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		deleteSelectedProductButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				deleteSelectedProductButtonActionPerformed(evt);
			}
		});
		toolBar1.add(deleteSelectedProductButton);

		subtotalLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
		subtotalLabel.setText("Subtotal Compra");

		subTotalField.setEditable(false);
		subTotalField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
		subTotalField.setEnabled(false);
		subTotalField.setFocusable(false);
		subTotalField.setMaximumSize(new java.awt.Dimension(100, 20));
		subTotalField.setMinimumSize(new java.awt.Dimension(100, 20));
		subTotalField.setPreferredSize(new java.awt.Dimension(100, 20));

		productsTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

		}, new String[] { "Cód. Int.", "Descripción", "Importe" }) {
			Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.String.class };
			boolean[] canEdit = new boolean[] { false, false, false };

			public Class getColumnClass(int columnIndex) {
				return types[columnIndex];
			}

			public boolean isCellEditable(int rowIndex, int columnIndex) {
				return canEdit[columnIndex];
			}
		});
		jScrollPane2.setViewportView(productsTable);
		productsTable.getColumnModel().getColumn(0).setMaxWidth(100);
		productsTable.getColumnModel().getColumn(2).setMaxWidth(200);

		javax.swing.GroupLayout productsPanelLayout = new javax.swing.GroupLayout(productsPanel);
		productsPanel.setLayout(productsPanelLayout);
		productsPanelLayout.setHorizontalGroup(productsPanelLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addComponent(toolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
				.addComponent(jScrollPane2)
				.addGroup(
						javax.swing.GroupLayout.Alignment.TRAILING,
						productsPanelLayout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE).addComponent(subtotalLabel).addGap(4, 4, 4)
								.addComponent(subTotalField, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
								.addContainerGap()));
		productsPanelLayout.setVerticalGroup(productsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				javax.swing.GroupLayout.Alignment.TRAILING,
				productsPanelLayout
						.createSequentialGroup()
						.addComponent(toolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(
								productsPanelLayout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
										.addComponent(subTotalField, javax.swing.GroupLayout.PREFERRED_SIZE, 28,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addComponent(subtotalLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)).addGap(0, 0, Short.MAX_VALUE)));

		initPurchaseButton.setText("IniciarCompra");
		initPurchaseButton.setBorder(null);
		initPurchaseButton.setEnabled(false);
		initPurchaseButton.setFocusable(false);
		initPurchaseButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		initPurchaseButton.setMaximumSize(new java.awt.Dimension(60, 15));
		initPurchaseButton.setMinimumSize(new java.awt.Dimension(60, 15));
		initPurchaseButton.setPreferredSize(new java.awt.Dimension(70, 70));
		initPurchaseButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		initPurchaseButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				initPurchaseButtonActionPerformed(evt);
			}
		});

		viewTotalsButton.setText("VisualizarTotal");
		viewTotalsButton.setBorder(null);
		viewTotalsButton.setEnabled(false);
		viewTotalsButton.setFocusable(false);
		viewTotalsButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		viewTotalsButton.setMaximumSize(new java.awt.Dimension(60, 15));
		viewTotalsButton.setMinimumSize(new java.awt.Dimension(60, 15));
		viewTotalsButton.setPreferredSize(new java.awt.Dimension(70, 70));
		viewTotalsButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		viewTotalsButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				viewTotalsButtonActionPerformed(evt);
			}
		});

		confirmPurchaseButton.setText("ConfirmarCompra");
		confirmPurchaseButton.setBorder(null);
		confirmPurchaseButton.setEnabled(false);
		confirmPurchaseButton.setFocusable(false);
		confirmPurchaseButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		confirmPurchaseButton.setMaximumSize(new java.awt.Dimension(60, 15));
		confirmPurchaseButton.setMinimumSize(new java.awt.Dimension(60, 15));
		confirmPurchaseButton.setPreferredSize(new java.awt.Dimension(70, 70));
		confirmPurchaseButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		confirmPurchaseButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				confirmPurchaseButtonActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout purchaseDetailsPanelLayout = new javax.swing.GroupLayout(purchaseDetailsPanel);
		purchaseDetailsPanel.setLayout(purchaseDetailsPanelLayout);
		purchaseDetailsPanelLayout.setHorizontalGroup(purchaseDetailsPanelLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addComponent(discountsPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE,
						javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
				.addComponent(productsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
				.addGroup(
						javax.swing.GroupLayout.Alignment.TRAILING,
						purchaseDetailsPanelLayout
								.createSequentialGroup()
								.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addGroup(
										purchaseDetailsPanelLayout
												.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
												.addGroup(
														purchaseDetailsPanelLayout
																.createSequentialGroup()
																.addComponent(initPurchaseButton, javax.swing.GroupLayout.PREFERRED_SIZE, 158,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																.addComponent(viewTotalsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 170,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																.addComponent(confirmPurchaseButton, javax.swing.GroupLayout.PREFERRED_SIZE, 158,
																		javax.swing.GroupLayout.PREFERRED_SIZE).addGap(6, 6, 6))
												.addComponent(totalLabel)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(totalsField, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
								.addContainerGap()));
		purchaseDetailsPanelLayout.setVerticalGroup(purchaseDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						purchaseDetailsPanelLayout
								.createSequentialGroup()
								.addComponent(productsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(discountsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										purchaseDetailsPanelLayout
												.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(totalsField, javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(totalLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 38,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										purchaseDetailsPanelLayout
												.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
												.addComponent(viewTotalsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(confirmPurchaseButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(initPurchaseButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50,
														javax.swing.GroupLayout.PREFERRED_SIZE))));

		companyDetailsPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

		dateLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		dateLabel.setText("Fecha");

		ticketNumberLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		ticketNumberLabel.setText("Nº Ticket");

		hourLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		hourLabel.setText("Tipo de Cliente");

		dateField.setEditable(false);
		dateField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
		dateField.setEnabled(false);
		dateField.setMaximumSize(new java.awt.Dimension(70, 20));
		dateField.setMinimumSize(new java.awt.Dimension(70, 20));
		dateField.setPreferredSize(new java.awt.Dimension(70, 20));

		companyLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		companyLabel.setText("Empresa");

		branchOfficeLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		branchOfficeLabel.setText("Sucursal");

		branchOfficeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "San Telmo" }));
		branchOfficeComboBox.setEnabled(false);
		branchOfficeComboBox.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				branchOfficeComboBoxActionPerformed(evt);
			}
		});

		companyNameField.setEditable(false);
		companyNameField.setHorizontalAlignment(javax.swing.JTextField.LEFT);
		companyNameField.setText("Hyper Market");
		companyNameField.setEnabled(false);

		ticketNumberField.setEditable(false);
		ticketNumberField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
		ticketNumberField.setEnabled(false);
		ticketNumberField.setMaximumSize(new java.awt.Dimension(70, 20));
		ticketNumberField.setMinimumSize(new java.awt.Dimension(70, 20));
		ticketNumberField.setPreferredSize(new java.awt.Dimension(70, 20));

		paymentLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		paymentLabel.setText("Forma de Pago");

		registerBoxLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		registerBoxLabel.setText("Caja Nº");

		registerBoxNumberField.setEditable(false);
		registerBoxNumberField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
		registerBoxNumberField.setText("1");
		registerBoxNumberField.setEnabled(false);

		bankLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		bankLabel.setText("Banco");

		paymentComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Efectivo", "Tarjeta" }));
		paymentComboBox.setEnabled(false);
		paymentComboBox.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				paymentComboBoxActionPerformed(evt);
			}
		});

		bankComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Santander Rio", "HSBC", "Citi", "Galicia", "Ciudad", "ICBC",
				"Provincia", " " }));
		bankComboBox.setEnabled(false);
		bankComboBox.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				bankComboBoxActionPerformed(evt);
			}
		});

		clientTypeBomboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Consumidor Final", "Jubilado" }));
		clientTypeBomboBox.setEnabled(false);
		clientTypeBomboBox.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				clientTypeBomboBoxActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout companyDetailsPanelLayout = new javax.swing.GroupLayout(companyDetailsPanel);
		companyDetailsPanel.setLayout(companyDetailsPanelLayout);
		companyDetailsPanelLayout
				.setHorizontalGroup(companyDetailsPanelLayout
						.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								companyDetailsPanelLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												companyDetailsPanelLayout
														.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																companyDetailsPanelLayout
																		.createSequentialGroup()
																		.addGroup(
																				companyDetailsPanelLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(ticketNumberLabel)
																						.addComponent(ticketNumberField,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				companyDetailsPanelLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING, false)
																						.addGroup(
																								companyDetailsPanelLayout.createSequentialGroup()
																										.addComponent(dateLabel).addGap(66, 66, 66))
																						.addGroup(
																								companyDetailsPanelLayout
																										.createSequentialGroup()
																										.addComponent(dateField,
																												javax.swing.GroupLayout.DEFAULT_SIZE,
																												javax.swing.GroupLayout.DEFAULT_SIZE,
																												Short.MAX_VALUE).addGap(12, 12, 12))))
														.addGroup(
																companyDetailsPanelLayout.createSequentialGroup().addComponent(companyLabel)
																		.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(companyNameField)
																		.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
										.addGroup(
												companyDetailsPanelLayout
														.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
														.addGroup(
																companyDetailsPanelLayout
																		.createSequentialGroup()
																		.addGroup(
																				companyDetailsPanelLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(hourLabel)
																						.addComponent(clientTypeBomboBox,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				companyDetailsPanelLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING, false)
																						.addComponent(paymentLabel,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
																						.addComponent(paymentComboBox, 0,
																								javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
														.addGroup(
																companyDetailsPanelLayout
																		.createSequentialGroup()
																		.addComponent(branchOfficeLabel)
																		.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(branchOfficeComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE,
																				Short.MAX_VALUE)))
										.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												companyDetailsPanelLayout
														.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
														.addGroup(
																companyDetailsPanelLayout.createSequentialGroup().addComponent(registerBoxLabel)
																		.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(registerBoxNumberField).addContainerGap())
														.addGroup(
																javax.swing.GroupLayout.Alignment.LEADING,
																companyDetailsPanelLayout
																		.createSequentialGroup()
																		.addGroup(
																				companyDetailsPanelLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING, false)
																						.addComponent(bankLabel,
																								javax.swing.GroupLayout.Alignment.LEADING,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
																						.addComponent(bankComboBox,
																								javax.swing.GroupLayout.Alignment.LEADING, 0,
																								javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
																		.addGap(0, 10, Short.MAX_VALUE)))));
		companyDetailsPanelLayout.setVerticalGroup(companyDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				companyDetailsPanelLayout
						.createSequentialGroup()
						.addContainerGap()
						.addGroup(
								companyDetailsPanelLayout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
										.addComponent(companyLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addComponent(companyNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addComponent(branchOfficeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 28,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addComponent(branchOfficeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
										.addComponent(registerBoxLabel)
										.addComponent(registerBoxNumberField, javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(
								companyDetailsPanelLayout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
										.addComponent(ticketNumberLabel)
										.addComponent(dateLabel)
										.addGroup(
												companyDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(hourLabel).addComponent(paymentLabel).addComponent(bankLabel)))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(
								companyDetailsPanelLayout
										.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
										.addComponent(ticketNumberField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)
										.addGroup(
												companyDetailsPanelLayout
														.createSequentialGroup()
														.addGroup(
																companyDetailsPanelLayout
																		.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
																		.addComponent(paymentComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addComponent(bankComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addComponent(clientTypeBomboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.PREFERRED_SIZE))
														.addGap(0, 0, Short.MAX_VALUE))
										.addComponent(dateField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)).addContainerGap()));

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup()
						.addContainerGap()
						.addGroup(
								layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
										.addComponent(purchaseDetailsPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
										.addGroup(
												layout.createSequentialGroup()
														.addComponent(companyDetailsPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
														.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
														.addComponent(registerBoxStatePanel, javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
						.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				javax.swing.GroupLayout.Alignment.TRAILING,
				layout.createSequentialGroup()
						.addContainerGap()
						.addGroup(
								layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
										.addComponent(companyDetailsPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
										.addComponent(registerBoxStatePanel, javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(purchaseDetailsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
								javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

		pack();
	}// </editor-fold>

	private void initDiscountsTable() {
		discountsTable.setBorder(null);
		discountsTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

		}, new String[] { "Porcentaje", "Condición" }) {
			Class[] types = new Class[] { java.lang.String.class, java.lang.String.class };
			boolean[] canEdit = new boolean[] { false, false };

			public Class getColumnClass(int columnIndex) {
				return types[columnIndex];
			}

			public boolean isCellEditable(int rowIndex, int columnIndex) {
				return canEdit[columnIndex];
			}
		});
	}

	private void initProductsTable() {
		productsTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

		}, new String[] { "Código Interno", "Descripción", "Importe" }) {
			Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.Double.class };
			boolean[] canEdit = new boolean[] { false, false, false };

			public Class getColumnClass(int columnIndex) {
				return types[columnIndex];
			}

			public boolean isCellEditable(int rowIndex, int columnIndex) {
				return canEdit[columnIndex];
			}
		});
	}

	private void cashRegisterStateButtonActionPerformed(java.awt.event.ActionEvent evt) {
		if (cashRegisterState.getText().equals(OPEN)) {
			closeRegisterBox();
		} else {
			openRegisterBox();
		}
	}

	private void closeRegisterBox() {
		registerBox.closeRegisterBox();
		registerBoxNumberField.setEnabled(false);
		companyNameField.setEnabled(false);
		initPurchaseButton.setEnabled(false);
		cashRegisterState.setText(CLOSED);
		cashRegisterState.setForeground(Color.RED);
	}

	private void openRegisterBox() {
		registerBox.openRegisterBox();
		registerBoxNumberField.setEnabled(true);
		companyNameField.setEnabled(true);
		initPurchaseButton.setEnabled(true);
		cashRegisterState.setText(OPEN);
		cashRegisterState.setForeground(Color.GREEN);
	}

	private void branchOfficeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
	}

	private void initPurchaseButtonActionPerformed(java.awt.event.ActionEvent evt) {
		if (bankComboBox.isEditable()) {
			registerBox.initPurchase(paymentComboBox.getSelectedItem().toString(), bankComboBox.getSelectedItem().toString(), clientTypeBomboBox
					.getSelectedItem().toString());
		} else {
			registerBox.initPurchase(paymentComboBox.getSelectedItem().toString(), null, clientTypeBomboBox.getSelectedItem().toString());
		}

		ticketNumberField.setText(registerBox.getTicketNumber().toString());
		enablePurchaseOrderComponents();
		initPurchaseButton.setEnabled(false);
	}

	private void enablePurchaseOrderComponents() {
		purchaseDetailsPanel.setEnabled(true);
		deleteSelectedProductButton.setEnabled(true);
		addNewProductButton.setEnabled(true);
		addNewCuponButton.setEnabled(true);
		addCuponField.setEnabled(true);
		addProductField.setEnabled(true);
		generateCupons.setEnabled(true);
		productsTable.setEnabled(true);
		ticketNumberField.setEnabled(true);
		ticketNumberField.setText(registerBox.getTicketNumber().toString());
		dateField.setEnabled(true);
		dateField.setText(registerBox.getDateFormatted());
		clientTypeBomboBox.setEnabled(true);
		paymentComboBox.setEnabled(true);
		bankComboBox.setEnabled(false);
		viewTotalsButton.setEnabled(true);
		confirmPurchaseButton.setEnabled(true);
	}

	private void viewTotalsButtonActionPerformed(java.awt.event.ActionEvent evt) {
		OrdenDeCompra purchaseOrder = registerBox.generatePurchaseOrder();
		if (purchaseOrder != null) {
			Venta sell = registerBox.generateSell(purchaseOrder);
			fillDiscountsTable(sell);
			if (registerBox.isGenerateCupon()) {
				cuponGeneratedField.setText(registerBox.getGeneratedCupon().getCodigo());
				cuponGeneratedField.setEnabled(true);
			}
		}
		subTotalField.setText(registerBox.getSubtotal().toString());
		totalDiscountsField.setText("(" + registerBox.getDiscountsTotal().toString() + ")");
		totalsField.setText(registerBox.getTotal().toString());
		disablePurchaseOrderComponents();
		enableTotalsFields();
	}

	private void fillDiscountsTable(Venta sell) {
		DefaultTableModel aModel = (DefaultTableModel) discountsTable.getModel();
		for (Oferta offer : sell.getOfertasProductosAplicada()) {
			Object[] content = { offer.getPorcentaje(), offer.getCondicionOferta() };
			aModel.addRow(content);
		}
		for (Oferta offer : sell.getOfertaVentaAplicada()) {
			Object[] content = { offer.getPorcentaje(), offer.getCondicionOferta() };
			aModel.addRow(content);
		}
	}

	private void confirmPurchaseButtonActionPerformed(java.awt.event.ActionEvent evt) {
		totalsField.setText("");
		subTotalField.setText("");
		totalDiscountsField.setText("");
		ticketNumberField.setText("");
		addProductField.setText("");
		cuponGeneratedField.setText("");
		addCuponField.setText("");
		disablePurchaseOrderComponents();
		disableTotalsFields();
		confirmPurchaseButton.setEnabled(false);
		initPurchaseButton.setEnabled(true);
		initProductsTable();
		initDiscountsTable();
		registerBox.finalizePurchase();
	}

	private void disablePurchaseOrderComponents() {
		purchaseDetailsPanel.setEnabled(false);
		deleteSelectedProductButton.setEnabled(false);
		addNewProductButton.setEnabled(false);
		addProductField.setEnabled(false);
		addNewProductButton.setEnabled(false);
		addNewCuponButton.setEnabled(false);
		generateCupons.setEnabled(false);
		addCuponField.setEnabled(false);
		productsTable.setEnabled(false);
		ticketNumberField.setEnabled(false);
		dateField.setEnabled(false);
		clientTypeBomboBox.setEnabled(false);
		paymentComboBox.setEnabled(false);
		bankComboBox.setEnabled(false);
		viewTotalsButton.setEnabled(false);
	}

	private void disableTotalsFields() {
		subTotalField.setEnabled(false);
		totalDiscountsField.setEnabled(false);
		totalsField.setEnabled(false);
		discountsPanel.setEnabled(false);
		discountsTable.setEnabled(false);
	}

	private void enableTotalsFields() {
		subTotalField.setEnabled(true);
		totalDiscountsField.setEnabled(true);
		totalsField.setEnabled(true);
		discountsPanel.setEnabled(true);
		discountsTable.setEnabled(true);
	}

	private void paymentComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
		if (paymentComboBox.getSelectedItem().equals(CREDIT_CARD)) {
			bankComboBox.setEnabled(true);
			registerBox.setBank(bankComboBox.getSelectedItem().toString());
		} else {
			bankComboBox.setEnabled(false);
			registerBox.setBank("");
		}
	}

	private void bankComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
		registerBox.setBank(bankComboBox.getSelectedItem().toString());
	}

	private void deleteSelectedProductButtonActionPerformed(java.awt.event.ActionEvent evt) {
		int column = productsTable.getSelectedColumn();
		int row = productsTable.getSelectedRow();
		if (!(row == -1 || column == -1)) {
			DefaultTableModel aModel = (DefaultTableModel) productsTable.getModel();
			String productId = aModel.getValueAt(row, column).toString();
			registerBox.removeProduct(productId);
			aModel.removeRow(row);
		}
	}

	private void addNewProductButtonActionPerformed(java.awt.event.ActionEvent evt) {

		String productId = addProductField.getText();
		Producto product = registerBox.addProduct(productId);
		if (product != null) {
			DefaultTableModel aModel = (DefaultTableModel) productsTable.getModel();
			Object[] rowData = new Object[] { product.getId(), product.getNombre(), product.getPrecio() };
			aModel.addRow(rowData);
			productsTable.setRowSelectionInterval(aModel.getRowCount() - 1, aModel.getRowCount() - 1);
		}
	}

	private void addNewCuponButtonActionPerformed(java.awt.event.ActionEvent evt) {

		String cuponId = addCuponField.getText();
		Cupon cupon = registerBox.addCupon(cuponId);
		if (cupon != null) {
			DefaultTableModel aModel = (DefaultTableModel) discountsTable.getModel();
			Object[] rowData = new Object[] { cupon.getCodigo(), "Cupon descuento", cupon.getMonto() };
			aModel.addRow(rowData);
			discountsTable.setRowSelectionInterval(aModel.getRowCount() - 1, aModel.getRowCount() - 1);
		}
	}

	private void clientTypeBomboBoxActionPerformed(java.awt.event.ActionEvent evt) {
		registerBox.setClientType(clientTypeBomboBox.getSelectedItem().toString());
	}

	private void generateCuponsActionPerformed(java.awt.event.ActionEvent evt) {
		registerBox.setGenerateCupon(generateCupons.isSelected());
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		/* Set the Nimbus look and feel */
		// <editor-fold defaultstate="collapsed"
		// desc=" Look and feel setting code (optional) ">
		/*
		 * If Nimbus (introduced in Java SE 6) is not available, stay with the
		 * default look and feel. For details see
		 * http://download.oracle.com/javase
		 * /tutorial/uiswing/lookandfeel/plaf.html
		 */
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(RegisterBoxUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(RegisterBoxUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(RegisterBoxUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(RegisterBoxUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		}
		// </editor-fold>

		/* Create and display the form */
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new RegisterBoxUI().setVisible(true);
			}
		});
	}

	// Variables declaration - do not modify
	private javax.swing.JTextField addCuponField;
	private javax.swing.JButton addNewCuponButton;
	private javax.swing.JButton addNewProductButton;
	private javax.swing.JTextField addProductField;
	private javax.swing.JComboBox bankComboBox;
	private javax.swing.JLabel bankLabel;
	private javax.swing.JComboBox branchOfficeComboBox;
	private javax.swing.JLabel branchOfficeLabel;
	private javax.swing.JTextField cashRegisterState;
	private javax.swing.JButton cashRegisterStateButton;
	private javax.swing.JComboBox clientTypeBomboBox;
	private javax.swing.JPanel companyDetailsPanel;
	private javax.swing.JLabel companyLabel;
	private javax.swing.JTextField companyNameField;
	private javax.swing.JButton confirmPurchaseButton;
	private javax.swing.JTextField cuponGeneratedField;
	private javax.swing.JLabel cuponGeneratedLabel;
	private javax.swing.JTextField dateField;
	private javax.swing.JLabel dateLabel;
	private javax.swing.JButton deleteSelectedProductButton;
	private javax.swing.JLabel discountsLabel;
	private javax.swing.JPanel discountsPanel;
	private javax.swing.JTable discountsTable;
	private javax.swing.JCheckBox generateCupons;
	private javax.swing.JLabel hourLabel;
	private javax.swing.JLabel idCuponLabel;
	private javax.swing.JLabel idProductLabel;
	private javax.swing.JButton initPurchaseButton;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JScrollPane jScrollPane2;
	private javax.swing.JToolBar.Separator jSeparator1;
	private javax.swing.JComboBox paymentComboBox;
	private javax.swing.JLabel paymentLabel;
	private javax.swing.JPanel productsPanel;
	private javax.swing.JTable productsTable;
	private javax.swing.JPanel purchaseDetailsPanel;
	private javax.swing.JLabel registerBoxLabel;
	private javax.swing.JTextField registerBoxNumberField;
	private javax.swing.JPanel registerBoxStatePanel;
	private javax.swing.JLabel registerStateLable;
	private javax.swing.JTextField subTotalField;
	private javax.swing.JLabel subtotalLabel;
	private javax.swing.JTextField ticketNumberField;
	private javax.swing.JLabel ticketNumberLabel;
	private javax.swing.JToolBar toolBar1;
	private javax.swing.JToolBar toolBar2;
	private javax.swing.JTextField totalDiscountsField;
	private javax.swing.JLabel totalLabel;
	private javax.swing.JTextField totalsField;
	private javax.swing.JButton viewTotalsButton;
	// End of variables declaration
}